package com.gsoe.base.exception;

import com.gsoe.base.model.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(UserException.class)
    public Result<String> userException(Exception x){
        log.error("-----User异常：{}-----",x.getMessage());
        return Result.fail(x.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public Result<String> exception(Exception x){
        log.error("-----未知异常：{}-----",x.getMessage());
        return Result.fail(x.getMessage());
    }

    @ExceptionHandler(MethodArgumentNotValidException.class)
    public Result<String> methodArgumentNotValidException(MethodArgumentNotValidException x){
        log.error("----参数不合法{}-----",x.getMessage());
        return Result.fail("参数不合法，请检查后重试");
    }

    @ExceptionHandler(ProblemException.class)
    public Result<String> problemException(ProblemException x){
        log.error("------Problem异常：{}-----",x.getMessage());
        return Result.fail(x.getMessage());
    }

    @ExceptionHandler(JudgeException.class)
    public Result<String> judgeException(JudgeException x){
        log.error("-----judge一次：{}-----",x.getMessage());
        return Result.fail(x.getMessage());
    }
}
